package com.mijie.homi.ns;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

import org.apache.log4j.PropertyConfigurator;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import sun.misc.Signal;
import sun.misc.SignalHandler;

import com.mijie.core.ApplicationProperties;
import com.mijie.homi.ns.core.HomiServer;
import com.mijie.util.MailUtil;

public class HomiNotificationServer {

	
	public static void main(String[] args) throws Exception{
		String confPath = System.getProperty("conf.path");
		if(confPath.endsWith("/")) confPath = confPath.substring(0,confPath.lastIndexOf("/"));
		ApplicationProperties.INSTANCE.load(new File(confPath+"/application.properties"));
		Properties log4jConf = new Properties();
		log4jConf.load(new FileInputStream(new File(confPath+"/log4j.properties")));
		PropertyConfigurator.configure(log4jConf);
		
		FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext("file:"+confPath+"/applicationContext.xml");
		HomiServer server = ctx.getBean(HomiServer.class);
		server.start();
		
		Runtime.getRuntime().addShutdownHook(new Thread(){
			@Override
			public void run() {
				String subject = "哈米 notification server was shutdown!";
				String content = "The notification server was shutdown,please check the server if it is non-artificially.";
				MailUtil.serverStatusReport(subject, content);
			}
		});
	}
}
